
/**
 * AppleIIGo
 * GCR 6&2 Disk Image class
 * (C) 2008 by Marc S. Ressl (mressl@umich.edu)
 * Released under the GPL
 */

#include "GCRDiskImage.h"

#ifndef GCR62DISKIMAGE_H
#define GCR62DISKIMAGE_H

typedef enum {
	GCR62_SECTORORDER_IMG,
	GCR62_SECTORORDER_DOS,
	GCR62_SECTORORDER_PRODOS,
	GCR62_SECTORORDER_CPM,
	GCR62_SECTORORDER_END,
};

#define GCR62_SECTOR_BYTENUM	0x100
#define GCR62_TRACK_SECTORNUM	0x10
#define GCR62_TRACK_BYTENUM		(GCR62_SECTOR_BYTENUM * GCR62_TRACK_SECTORNUM)

class GCR62DiskImage : public GCRDiskImage {
public:
	static bool isDiskImageValid(UINT32 diskType, UINT32 diskImageByteNum);
	
	GCR62DiskImage(char * diskImagePath,
				   UINT32 diskImageOffset,
				   UINT32 diskImageByteNum,
				   UINT32 diskImageSectorOrder,
				   UINT8 diskImageVolume,
				   bool isWriteProtectionForced);
	~GCR62DiskImage();
	
protected:
	void getDiskTrack(UINT32 * trackIndex, UINT32 * headIndex, 
					  UINT32 * diskImageTrackByteNum,
					  UINT32 diskImageTrackIndex);
	void getDiskImageTrack(UINT32 * diskImageTrackIndex,
						   UINT32 * diskImageTrackByteNum,
						   UINT32 trackIndex, UINT32 headIndex);
	
	void writeAddressField(UINT32 diskImageTrackIndex, UINT32 sectorIndex);
	void writeDataField(UINT8 * sectorData);
	void writeTrack(UINT32 diskImageTrackIndex, UINT8 * diskImageTrackData);
	
	bool readAddressField(UINT32 diskImageTrackIndex, UINT32 sectorIndex);
	bool readDataField(UINT8 * sectorData);
	bool readTrack(UINT32 diskImageTrackIndex, UINT8 * diskImageTrackData);
	
private:
	UINT32 diskImageOffset;
	
	UINT32 diskImageTrackNum;
	UINT32 gcrSectorOrder;
	UINT8 gcrVolume;
};

#endif
